// 页面加载时立即执行的代码
window.onload = function () {
    console.log("Page loaded, executing request...");
    fetchData();
};

function fetchData() {
    fetch('/api/user/queryuserbytoken?token=' + getCookie('token'))
        .then(response => response.json())
        .then(data => {
            console.log("Data received:", data);
            document.getElementById('wel').innerHTML = "欢迎您！" + data.userName ;

        })
        .catch(error => console.error("Error fetching data:", error));
}


function getCookie(name) {
    const cookies = document.cookie.split('; ');
    for (let cookie of cookies) {
        const [key, value] = cookie.split('=');
        if (key === name) {
            return decodeURIComponent(value);
        }
    }
    return null;
}
